import { Hero } from '../hero-detail/hero.model'
import { LoggerService } from './loggerService'

export class HeroService {

    private heroes: Hero[] = [];
    // private logger = new LoggerService();

    constructor(
        private logger: LoggerService
    ) { }

    addHero(newHero: Hero): boolean {
        if (!newHero || !newHero.name) {
            this.logger.warn(`HeroService add a new hero ${newHero} failed!`);
            return false;
        }

        this.heroes.push(newHero);
        this.logger.log(`HeroService add a new hero ${newHero} successed!`);

        return true;
    }

    getAllHeroes(): Hero[] {
        if (!this.heroes || this.heroes.length == 0) {
            this.heroes.push(new Hero(100, "Test Hero 100"));
            this.heroes.push(new Hero(200, "Test Hero 200"));
        }

        this.logger.log(`HeroService getAllHeroes ${this.heroes.length} !`);

        return this.heroes;
    }

}